package uri.model.collection;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import uri.model.BoardVO;
import uri.model.CommentVO;
import uri.model.FileVO;

@Repository
public class CollectionDAOImpl implements CollectionDAO {
	
	@Resource(name="sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;

	@Override
	public void writeCollection(BoardVO bvo) {
		sqlSessionTemplate.insert("collection.writeCollection",bvo);
	}

	@Override
	public void fileUpload(FileVO fvo) {
		sqlSessionTemplate.insert("collection.fileUpload",fvo);
	}

	@Override
	public BoardVO detailCollectionNoHit(String no) {
		return sqlSessionTemplate.selectOne("collection.detailCollectionNoHit",no);
	}

	@Override
	public List<FileVO> fileInfo(String textNo) {
		return (List) sqlSessionTemplate.selectList("collection.fileInfo",textNo);
	}

	@Override
	public List<BoardVO> contentList(int nowPage1) {
		return sqlSessionTemplate.selectList("collection.contentList",nowPage1);
	}

	@Override
	public int getAllContentCount() {
		return sqlSessionTemplate.selectOne("collection.getAllContentCount");
	}

	@Override
	public void hitPlus(String no) {
		sqlSessionTemplate.update("collection.hitPlus",no);
	}

	@Override
	public void deleteCollection(String no) {
		sqlSessionTemplate.delete("collection.deleteCollection",no);
	}

	@Override
	public void deleteFiles(String no) {
		sqlSessionTemplate.delete("collection.deleteFiles",no);
	}

	@Override
	public List<String> findFileNameByNo(String no) {
		return sqlSessionTemplate.selectList("collection.findFileNameByNo", no);
	}

	@Override
	public int writeComment(uri.model.collection.CommentVO cvo) {
		return sqlSessionTemplate.insert("collection.writeComment",cvo);
	}

	@Override
	public List<uri.model.collection.CommentVO> getAllComment(String no) {
		return sqlSessionTemplate.selectList("collection.getAllComment",no);
	}

	@Override
	public int deleteComment(String no) {
		return sqlSessionTemplate.delete("collection.deleteComment",no);
	}

	@Override
	public int updateComment(uri.model.collection.CommentVO cvo) {
		return sqlSessionTemplate.update("collection.updateComment",cvo);
	}

	@Override
	public void updateCollection(BoardVO bvo) {
		sqlSessionTemplate.update("collection.updateCollection",bvo);
	}

	@Override
	public void updateFileList(FileVO fvo) {
		sqlSessionTemplate.update("collection.updateFileList",fvo);
	}

	@Override
	public String getFileNameByNo(String no) {
		return sqlSessionTemplate.selectOne("collection.getFileNameByNo",no);
	}

	@Override
	public void updateFile(FileVO updateFileInfo) {
		sqlSessionTemplate.update("collection.updateFile",updateFileInfo);
	}

	@Override
	public void deleteFileByno(String no) {
		sqlSessionTemplate.delete("collection.deleteFileByno",no);
	}

	@Override
	public void replyWriteGo(BoardVO bvo) {
		sqlSessionTemplate.insert("collection.replyWrite",bvo);
	}

	@Override
	public void updateRestep(BoardVO bvo) {
		HashMap map = new HashMap();
		map.put("ref", bvo.getRef());
		map.put("restep", bvo.getRestep());
		sqlSessionTemplate.update("collection.updateRestep",map);
	}

	@Override
	public void updateRef(BoardVO bvo) {
		sqlSessionTemplate.update("collection.updateRef",bvo);
	}

	@Override
	public List<BoardVO> findCollectionByTitle(HashMap map) {
		return sqlSessionTemplate.selectList("collection.findCollectionByTitle",map);
	}

	@Override
	public List<BoardVO> findCollectionByContent(HashMap map) {
		return sqlSessionTemplate.selectList("collection.findCollectionByContent",map);
	}

	@Override
	public List<BoardVO> findCollectionByTitleAndContent(HashMap map) {
		return sqlSessionTemplate.selectList("collection.findCollectionByTitleAndContent",map);
	}

	@Override
	public void deleteFile(String no) {
		sqlSessionTemplate.delete("collection.deleteFile",no);
	}

	@Override
	public void updateLike(String no) {
		sqlSessionTemplate.update("collection.updateLike",no);
	}

	
}
